/*
 * Created on Fri Sep 29 2017
 * 
 * Copyright (c) 2017 jianglinjie
 */
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.checkPass = checkPass;
exports.checkUserName = checkUserName;
exports.isPhone = isPhone;
exports.checkGender = checkGender;
exports.checkAvatar = checkAvatar;
exports.checkNickName = checkNickName;
exports.checkCaptchaBusiness = checkCaptchaBusiness;

var _GenderTypes = require('../constants/GenderTypes');

var GenderTypes = _interopRequireWildcard(_GenderTypes);

var _CaptchaBusiness = require('../constants/CaptchaBusiness');

var CaptchaBusiness = _interopRequireWildcard(_CaptchaBusiness);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

/**
 * 是否是合法的密码
 * 
 * @export
 * @param {string} [pass=''] 
 * @returns {boolean} 
 */
function checkPass() {
  var pass = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

  var regx = /^[a-zA-Z0-9]{6,256}$/; //6到20位 字母和数字组成
  if (!regx.test(pass)) {
    return false;
  }

  return true;
}

/**
 * 是否是合法的用户名
 * 
 * @export
 * @param {string} [pass=''] 
 * @returns {boolean} 
 */
function checkUserName() {
  var userName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

  var regx = /^[a-zA-Z]{1}([a-zA-Z0-9]|[-]|[_]){5,256}$/; //5到20位 字母和数字组成中划线 下划线 字母开头
  if (!regx.test(userName)) {
    return false;
  }

  return true;
}

/**
 * 是否是电话号码
 * 
 * @export
 * @param {string} [str=''] 
 * @returns {boolean} 
 */
function isPhone() {
  var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

  var regx = /^[0-9]{11}$/;
  if (!regx.test(str)) {
    return false;
  }

  return true;
}

function checkGender() {
  var gender = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  var _iteratorNormalCompletion = true;
  var _didIteratorError = false;
  var _iteratorError = undefined;

  try {
    for (var _iterator = Object.keys(GenderTypes)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
      var key = _step.value;

      if (GenderTypes[key] === gender) {
        return true;
      }
    }
  } catch (err) {
    _didIteratorError = true;
    _iteratorError = err;
  } finally {
    try {
      if (!_iteratorNormalCompletion && _iterator.return) {
        _iterator.return();
      }
    } finally {
      if (_didIteratorError) {
        throw _iteratorError;
      }
    }
  }

  return false;
}

function checkAvatar() {
  var avatar = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

  var regx = /^http/;
  if (!regx.test(avatar)) {
    return false;
  }

  return true;
}

function checkNickName() {
  var nickName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

  //不能为空 或超过30个字符
  if (!nickName || nickName.length > 30) {
    return false;
  }

  return true;
}

function checkCaptchaBusiness() {
  var business = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  var _iteratorNormalCompletion2 = true;
  var _didIteratorError2 = false;
  var _iteratorError2 = undefined;

  try {
    for (var _iterator2 = Object.keys(CaptchaBusiness)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
      var key = _step2.value;

      if (CaptchaBusiness[key] === business) {
        return true;
      }
    }
  } catch (err) {
    _didIteratorError2 = true;
    _iteratorError2 = err;
  } finally {
    try {
      if (!_iteratorNormalCompletion2 && _iterator2.return) {
        _iterator2.return();
      }
    } finally {
      if (_didIteratorError2) {
        throw _iteratorError2;
      }
    }
  }

  return false;
}